<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2017/12/13
  Time: 16:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<style>
  .entityDiv{
    margin: 5px 0 20px 50px;
  }
  #form_modulePower_input>div{
    border: 1px solid #CCC;
    height: 300px;
    overflow: auto;
  }
</style>

<legend style="padding: 0; border: none">
  <span class="label label-primary">模块是阅读权限，表单是新建权限</span>
</legend>

<div class="panel" style="margin: 0">
  <div class="panel-body" style="padding: 0">
    <form id="form_modulePower_input" class="form-horizontal">
      <input type="hidden" name="userId" value="${userId}"/>
      <input type="hidden" name="modulePowerId" value="${modulePower.id}"/>

      <%--<c:forEach var="d" items="${data}" varStatus="dStatus">--%>
        <%--<div class="checkbox">--%>
          <%--<input type="checkbox" id="module${dStatus.index}" class="magic-checkbox" name="module" value="${d.moduleName}" <c:if test="${fn:indexOf(modulePower.moduleName,d.moduleName)>=0}">checked</c:if> >--%>
          <%--<label class="moduleLabel" for="module${dStatus.index}">${d.moduleName}</label>--%>
          <%--<div class="entityDiv">--%>
            <%--<c:forEach var="e" items="${d.entityMap}" varStatus="eStatus">--%>
              <%--<input type="checkbox" id="${e.entity.key}entity${eStatus.index}" class="magic-checkbox" name="entity" value="${e.entity.key}" <c:if test="${fn:indexOf(modulePower.entityName,e.entity.key)>=0}">checked</c:if> >--%>
              <%--<label class="entityLabel" for="${e.entity.key}entity${eStatus.index}">${e.entity.value}</label>--%>
            <%--</c:forEach>--%>
          <%--</div>--%>
        <%--</div>--%>
      <%--</c:forEach>--%>

      <%--模块--%>
      <div class="col-md-6 col-xs-6" style="padding: 0;">
        <ul class="list-group">
          <c:forEach var="d" items="${data}" varStatus="dStatus">
            <li class="list-group-item">
              <input type="checkbox" id="module${dStatus.index}" class="magic-checkbox" name="module" value="${d.moduleName}" <c:if test="${fn:indexOf(modulePower.moduleName,d.moduleName)>=0}">checked</c:if> >
              <label class="moduleLabel" for="module${dStatus.index}">${d.moduleName}</label>
            </li>
          </c:forEach>
        </ul>
      </div>

      <%--表单--%>
      <div class="col-md-6 col-xs-6" style="padding: 0">
        <ul class="list-group" id="entityUl">
          <c:forEach var="d" items="${data}" varStatus="dStatus">
            <c:if test="${fn:indexOf(modulePower.moduleName,d.moduleName)>=0}">
              <c:forEach var="e" items="${d.entityMap}" varStatus="eStatus">
                <li class="list-group-item module${dStatus.index}">
                  <input type="checkbox" id="${e.entity.key}entity${eStatus.index}" class="magic-checkbox" name="entity" value="${e.entity.key}" <c:if test="${fn:indexOf(modulePower.entityName,e.entity.key)>=0}">checked</c:if> >
                  <label class="entityLabel" for="${e.entity.key}entity${eStatus.index}">${d.moduleName} - ${e.entity.value}</label>
                </li>
              </c:forEach>
            </c:if>
          </c:forEach>
        </ul>
      </div>


    </form>
  </div>
</div>


<script>

  $(":checkbox[name='module']").click(function(){
    var cName=$(this).attr("id");
    var mName=$(this).val();
    if(!$(this).is(':checked')){
      $("."+cName+"").remove();
    }else{
      if($("."+cName+"").size()<=0){
        __ajax_get("<%=path%>/com/modulePower/getFormList",{moduleName:mName},function(data){
          for(var i=0;i<data.length;i++){
            var newLi='<li class="list-group-item '+cName+'">'
                    +'<input type="checkbox" id="'+data[i].key+'entity'+i+'" class="magic-checkbox" name="entity" value="'+data[i].key+'">'
                    +'<label class="entityLabel" for="'+data[i].key+'entity'+i+'">'+mName+' - '+data[i].value+'</label>'
                    +'</li>';
            $("#entityUl").append(newLi);
          }
        })
      }
    }
  });


  function fn_modulePower_edit(){

    if(!$(":checked[name='module']").val()){
      __toastr_error("至少选择一个模块");
      return false;
    }

    if(!$(":checked[name='entity']").val()){
      __toastr_error("至少选择一个表单");
      return false;
    }

    __form_save("form_modulePower_input","<%=path%>/com/modulePower/edit");
  }

</script>